package com.cai.io.demo;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class ReadStringDemo {
    public static void main(String[] args) throws IOException {
        File file=new File("demo.txt");
        long fileSize = file.length();
        FileInputStream fis = new FileInputStream(file);
        //读取文件
        byte[] data = new byte[(int)fileSize];
        fis.read(data);

        //打印文件
        String str = new String(data, StandardCharsets.UTF_8);
        System.out.println(str);
    }
}
